import Vue from 'vue'
import VueRouter from 'vue-router'
import films from '@/views/films'
import cinemas from '@/views/cinemas'
import center from '@/views/center'
import nowplay from "@/views/films/nowplay";
import comingsoon from "@/views/films/comingsoon";
import detail from "@/views/detail";
import search from "@/views/search";
import login from "@/views/login";
import city from "@/views/city";

Vue.use(VueRouter)

// import Cookies from "js-cookie";
// Vue.use(Cookies)

import {mapState} from "vuex";
import dingdan from "@/views/dingdan";

const routes = [
  {
    path: '/films',
    component: films,
    children:[
      {
        path: '/films/nowplay',
        component:nowplay
      },
      {
        path: '/films/comingsoon',
        component: comingsoon
      },
      {
        path: '/detail',
        component: detail
      },
      {     //重定向
        path: '/films',
        redirect: '/films/nowplay'
      }
    ]
  },
  {
    name: 'inb',    //命名路由
    path: '/detail/:myid/:posts',  //动态二级路由
    component: detail
  },
  {
    path: '/cinemas',
    component: cinemas,
  },
  {
    path: '/cinemas/search',
    component: search,
  },
  {
    path: '/center',
    component: center,
    meta:{
      ssss:true
    }
    //局部路由拦截
    // beforeEnter:(to,from,next) => {
    //   if (localStorage.getItem('inb')) {
    //     next()
    //   }else {
    //     next('/login')
    //   }
    // }
  },
  {
    path: '/dingdan',
    component: () =>import('@/views/dingdan'),
  },
  {
    path: '/order',
    //路由懒加载，当访问/order路径值组件才加载
    component: () =>import('@/views/order'),
    meta:{
      ssss:true
    }
  },
  {
    path: '/login',
    component: login
  },
  {
    path: '/city',
    component: city
  },
  {     //重定向
    path: '*',
    redirect: '/films'
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//axios拦截器    登录信息验证
// router.beforeEach((to, from, next) =>{
//
//   if(to.meta.ssss){
//     if (Cookies.get('inb')){
//       next()
//     }else {
//       next('/login')
//     }
//     }else {
//       next()
//     }
// })


    // if (localStorage.getItem('inb')){
    //   next()
    // }else {
    //   next('/login')

      //记录路由原，转跳到进入之前的页面
      // next({
      //   path: '/login',
      //   query: {aaa:to.fullPath}
      // })
    // }

export default router
